package main

import "fmt"

func main() {
	outs := generate(7)
	print(outs)
	fmt.Println(getRow(6))
}

func print(nums [][]int) {
	for _, vo := range nums {
		for _, vi := range vo {
			fmt.Print(vi, " ")
		}
		fmt.Println()
	}
}

func generate(numsRow int) [][]int {
	ans := make([][]int, numsRow)
	for i := 0; i < numsRow; i++ {
		ans[i] = make([]int, i+1)
		ans[i][0] = 1
		ans[i][i] = 1
		for j := 1; j < i; j++ {
			ans[i][j] = ans[i-1][j-1] + ans[i-1][j]
		}
	}
	return ans
}

func getRow(rowIndex int) []int {
	ans := make([]int, rowIndex+1)
	ans[0] = 1
	for i := 1; i < rowIndex+1; i++ {
		tmp := 1
		for j := 1; j < i; j++ {
			tmp, ans[j-1] = ans[j]+ans[j-1], tmp
		}
		ans[i-1] = tmp
		ans[i] = 1
	}
	return ans
}
